package MainTest;

/**
 * Created by xuyi on 2017/2/13.
 */
public class TreeisSymmetrical {

    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    public static void main(String[] args) {
        int a=10; double b=3.14 ;
        double v = 'A' + a + b;

        System.out.println(v);

    }


//    public static void main(String[] args) {
//        TreeNode treeNode1 = new TreeisSymmetrical().new TreeNode(1);
//        TreeNode treeNode2 = new TreeisSymmetrical().new TreeNode(2);
//
//        treeNode1.left = treeNode2;
////        treeNode1.right = treeNode2;
//        Solution solution = new TreeisSymmetrical().new Solution();
//        boolean symmetrical = solution.isSymmetrical(treeNode1);
//        System.out.println(symmetrical);
//    }

    public class Solution {
        boolean isSymmetrical(TreeNode pRoot) {
            TreeNode mirror = this.getMirror(pRoot);
            return this.isSymmetrical(pRoot, mirror);
        }
        boolean isSymmetrical(TreeNode pRoot, TreeNode mirror) {
            if (pRoot == null && mirror == null) {
                return true;
            } else if (pRoot == null || mirror == null) {
                return false;
            }
            if (pRoot.val == mirror.val) {
                return this.isSymmetrical(pRoot.left, mirror.left) && this.isSymmetrical(pRoot.right, mirror.right);
            }
            return false;
        }

        TreeNode getMirror(TreeNode treeNode) {
            if (treeNode == null) {
                return treeNode;
            }
            TreeNode root = new TreeNode(treeNode.val);
            root.right = getMirror(treeNode.left);
            root.left = getMirror(treeNode.right);
            return treeNode;
        }

    }


}
